<?php

namespace app\home\controller;

use think\Cookie;
use think\Db;

class Rebate extends Base
{
    //输入京东/拼多多链接查询佣金
    public function checkCommission(){
        $urls =  input('urls');
        $uid = $this->user['id'];
        $time = time();
        $data = [
            'uid' => $uid,
            'ourl' => $urls,
            'timestamp' => $time,
            'sign' => md5($time . $uid . config('urlsKey')),
        ];
        //查询佣金
        $result = curlPosts(config('jpurls')."/jd/checkyongjin",$data);
        //链接获取转链
        $rel= curlPosts(config('jpurls')."/jd/switchurl",$data);

        return outputJson(0,'ok',['list'=>$result['data'],'urls'=>$rel['data']]);
    }

    //输入京东/拼多多链接随机查询一条  新手任务
    public function randomjd(){
        $uid = $this->user['id'];
        $time = time();
        $data = [
            'uid' => $uid,
            'timestamp' => $time,
            'sign' => md5($time . $uid . config('urlsKey')),
        ];
        $result = curlPosts(config('jpurls')."/jd/randomjd",$data);
        return outputJson(0,'ok',['list'=>$result['data']]);
    }

    //输入京东/拼多多订单编号领取佣金
    public function matchorder(){
        $uid = $this->user['id'];
        $time = time();
        $data = [
            'uid' => $uid,
            'timestamp' => $time,
            'sign' => md5($time . $uid . config('urlsKey')),
            'oid' => input('oid'),
        ];
        $result = curlPosts(config('jpurls')."/jd/matchorder",$data);
        if($result['errcode'] == 0){
            return outputJson(0,'ok');
        }
        if($result['errcode'] == 1){
            return outputJson(100,$result['errmsg']);
        }
        return outputJson(100,'没有查到订单号');
    }
    //获取京东返佣订单列表
    public function getjdorder(){
        $uid = $this->user['id'];
        $time = time();
        $data = [
            'uid' => $uid,
            'timestamp' => $time,
            'sign' => md5($time . $uid . config('urlsKey'))
        ];
        $result = curlPosts(config('jpurls')."/jd/getjdorder",$data);
        return outputJson(0,'ok',['list'=> $result['data'] ??[]]);
    }

    //获取拼多多返佣订单列表
    public function getpddorder(){
        $uid = $this->user['id'];
        $time = time();
        $data = [
            'uid' => $uid,
            'timestamp' => $time,
            'sign' => md5($time . $uid . config('urlsKey'))
        ];
        $result = curlPosts(config('jpurls')."/pdd/getpddorder",$data);
        return outputJson(0,'ok',['list'=> $result['data'] ??[]]);
    }
}